package net.sf.nlp.ltag.parser.earley;

import net.sf.nlp.ltag.data.ArrayKey;
import net.sf.nlp.ltag.data.LTAGNode;
import net.sf.nlp.ltag.data.LTAGTree;
import net.sf.nlp.ltag.parser.LTAGState;

public class EarleyState extends LTAGState implements Cloneable{
	
	public enum POSITION {LA, LB, RA, RB};
	
	private POSITION pos = POSITION.LA;
	
	private int l = 0;
	private int fl = -1;
	private int fr = -1;
	private LTAGNode star = null;
	private int tl = -1;
	private int bl = -1;
	
	private int step;
		
	public EarleyState(LTAGTree tree, int step)
	{
		super(tree);
		this.step = step;
	}
	
	public POSITION getPos() {
		return pos;
	}
	public void setPos(POSITION pos) {
		this.pos = pos;
	}
	public int getL() {
		return l;
	}
	public void setL(int l) {
		this.l = l;
	}
	public int getFl() {
		return fl;
	}
	public void setFl(int fl) {
		this.fl = fl;
	}
	public int getFr() {
		return fr;
	}
	public void setFr(int fr) {
		this.fr = fr;
	}
	public LTAGNode getStar() {
		return star;
	}
	public void setStar(LTAGNode star) {
		this.star = star;
	}
	public int getTl() {
		return tl;
	}
	public void setTl(int tl) {
		this.tl = tl;
	}
	public int getBl() {
		return bl;
	}
	public void setBl(int bl) {
		this.bl = bl;
	}
	public int getStep() {
		return step;
	}
	public void setStep(int step) {
		this.step = step;
	}
	public String toString()
	{
		StringBuffer sb = new StringBuffer();
		
		sb.append(id).append(".");
		sb.append("[");
		sb.append(tree.getRoot().getNodeText());
		if (tree.getId() != null)
			sb.append("-").append(tree.getId());
		sb.append(", ");
		sb.append(node.getNodeText());
		sb.append("(").append(node.getLocation()).append(")");
		if (node.getWord() != null)
			sb.append("#").append(node.getWord().getLexical());
		sb.append(", ");
		sb.append(pos.name()).append(", ");
		sb.append(l).append(", ");
		sb.append(fl).append(", ");
		sb.append(fr).append(", ");
		if (star != null)
		{
			sb.append(star.getNodeText());
			sb.append("(").append(star.getLocation()).append(")");
			sb.append(",");
		}
		else
			sb.append("-, ");
		sb.append(tl).append(", ");
		sb.append(bl);
		sb.append("]");
		
		sb.append("(");
		if (previousState != null)
			sb.append(previousState.getId());
		else
			sb.append("");
		sb.append("->").append(id).append(")");
		
		return sb.toString();
	}
	
	public ArrayKey getStatisticKey()
	{
		if (node.getLocation() != 0 && pos != POSITION.LA)
			return null;
		
		return super.getStatisticKey();
	}
	
	/*
	public boolean equals1(EarleyState state)
	{
		if (this.tree.getId() != state.getTree().getId())
			return false;
		if (this.pos != state.getPos())
			return false;
		if (this.getNode().getLocation() != state.getNode().getLocation())
			return false;
		
		if (this.operatorHistory != null && state.getOperatorHistory() != null)
		{
			if (this.operatorHistory.size() != state.getOperatorHistory().size())
				return false;
			
			for (int i = 0; i < this.operatorHistory.size(); i++)
			{
				Operator operator1 = this.operatorHistory.get(i);
				
				if (!operator1.equals(state.getOperatorHistory().get(i)))
					return false;
			}
		}
		
		return false;
	}*/
	
}
